﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using thinger.VisionModels;

namespace thinger.VisionDemo
{
    public partial class FrmShow : Form
    {
        private Timer updateTimer = new Timer();
        public FrmShow()
        {
            InitializeComponent();
            this.updateTimer.Interval = 100;
            this.updateTimer.Tick += UpdateTimer_Tick;
            this.updateTimer.Start();
        }

        private void FrmShow_Resize(object sender, EventArgs e)
        {
            if (this.WindowState == FormWindowState.Maximized)
            {
                Console.WriteLine($"最大化。。。。。");
            }
            //panel1.Width = 1402;
            //panel1.Height = 768;
            Mainpro.Instance.CenterControlInParent(panel1);
        }

        private void FrmShow_Load(object sender, EventArgs e)
        {
            ucqu1.IsFlow = false;
            ucjian1.IsFlow = false;
            ucda1.IsFlow = false;
            ucdu1.IsFlow = false;
            ucxia1.IsFlow = false;


            ucqu2.IsFlow = false;
            ucjian2.IsFlow = false;
            ucda2.IsFlow = false;
            ucdu2.IsFlow = false;
            ucxia2.IsFlow = false;

        }
        private void UpdateTimer_Tick(object sender, EventArgs e)
        {
            UpdateData();
        }


        private string GetTimeCount(DateTime t1, DateTime t2)
        {
            TimeSpan elapsed = t2 - t1;
            return "耗时：" + ((int)elapsed.TotalSeconds).ToString() + " 秒";
        }
        #region 搬运1
        private void qu1()
        {
            if (GlobalVar.Instance.TimeStepData1.quSatrtTime.Year > 1)
            {
                if (GlobalVar.Instance.TimeStepData1.quEndTime.Year > 1)
                {
                    lab_quliao1.Text = $"搬运1-取料完成";
                    lab_quliao1Time.Text = $"{GetTimeCount(GlobalVar.Instance.TimeStepData1.quSatrtTime, GlobalVar.Instance.TimeStepData1.quEndTime)}";
                }
                else
                {
                    lab_quliao1.Text = $"搬运1-取料中";
                    lab_quliao1Time.Text = $"{GetTimeCount(GlobalVar.Instance.TimeStepData1.quSatrtTime, DateTime.Now)}";
                    lab_quliao1.Visible = true;
                    lab_quliao1Time.Visible = true;
                    lab_jiance1.Visible = false;
                    lab_jiance1Time.Visible = false;
                    lab_dama1.Visible = false;
                    lab_dama1Time.Visible = false;
                    lab_duma1.Visible = false;
                    lab_duma1Time.Visible = false;
                    lab_xialiao1.Visible = false;
                    lab_xialiao1Time.Visible = false;

                    ucqu1.IsFlow = true;
                }
                jian1();


            }
            else
            {
                lab_quliao1.Visible = false;
                lab_quliao1Time.Visible = false;
                lab_jiance1.Visible = false;
                lab_jiance1Time.Visible = false;
                lab_dama1.Visible = false;
                lab_dama1Time.Visible = false;
                lab_duma1.Visible = false;
                lab_duma1Time.Visible = false;
                lab_xialiao1.Visible = false;
                lab_xialiao1Time.Visible = false;

                ucqu1.IsFlow = false;
                ucjian1.IsFlow = false;
                ucda1.IsFlow = false;
                ucdu1.IsFlow = false;
                ucxia1.IsFlow = false;


            }
        }

        private void jian1()
        {
            if (GlobalVar.Instance.TimeStepData1.checkSatrtTime.Year > 1)
            {
                if (GlobalVar.Instance.TimeStepData1.checkEndTime.Year > 1)
                {
                    lab_quliao1.Text = $"搬运1-检测完成";
                    lab_quliao1Time.Text = $"{GetTimeCount(GlobalVar.Instance.TimeStepData1.checkSatrtTime, GlobalVar.Instance.TimeStepData1.checkEndTime)}";
                }
                else
                {
                    lab_jiance1.Text = $"搬运1-检测中";
                    lab_jiance1Time.Text = $"{GetTimeCount(GlobalVar.Instance.TimeStepData1.checkSatrtTime, DateTime.Now)}";
                    lab_jiance1.Visible = true;
                    lab_jiance1Time.Visible = true;
                    lab_dama1.Visible = false;
                    lab_dama1Time.Visible = false;
                    lab_duma1.Visible = false;
                    lab_duma1Time.Visible = false;
                    lab_xialiao1.Visible = false;
                    lab_xialiao1Time.Visible = false;

                    ucjian1.IsFlow = true;
                }

                dama1();
            }
            else
            {
                lab_dama1.Visible = false;
                lab_dama1Time.Visible = false;
                lab_duma1.Visible = false;
                lab_duma1Time.Visible = false;
                lab_xialiao1.Visible = false;
                lab_xialiao1Time.Visible = false;
            }
        }

        private void dama1()
        {
            if (GlobalVar.Instance.TimeStepData1.printSatrtTime.Year > 1)
            {
                if (GlobalVar.Instance.TimeStepData1.printEndTime.Year > 1)
                {
                    lab_dama1.Text = $"搬运1-打码完成";
                    lab_dama1Time.Text = $"{GetTimeCount(GlobalVar.Instance.TimeStepData1.printSatrtTime, GlobalVar.Instance.TimeStepData1.printEndTime)}";
                }
                else
                {
                    lab_dama1.Text = $"搬运1-打码中";
                    lab_dama1Time.Text = $"{GetTimeCount(GlobalVar.Instance.TimeStepData1.printSatrtTime, DateTime.Now)}";
                    lab_dama1.Visible = true;
                    lab_dama1Time.Visible = true;
                    lab_duma1.Visible = false;
                    lab_duma1Time.Visible = false;
                    lab_xialiao1.Visible = false;
                    lab_xialiao1Time.Visible = false;

                    ucda1.IsFlow = true;
                }
                duma1();
            }
            else
            {
                lab_duma1.Visible = false;
                lab_duma1Time.Visible = false;
                lab_xialiao1.Visible = false;
                lab_xialiao1Time.Visible = false;
            }
        }

        private void duma1()
        {
            if (GlobalVar.Instance.TimeStepData1.readSatrtTime.Year > 1)
            {
                if (GlobalVar.Instance.TimeStepData1.readEndTime.Year > 1)
                {
                    lab_duma1.Text = $"搬运1-读码完成";
                    lab_duma1Time.Text = $"{GetTimeCount(GlobalVar.Instance.TimeStepData1.readSatrtTime, GlobalVar.Instance.TimeStepData1.readEndTime)}";
                }
                else
                {
                    lab_duma1.Text = $"搬运1-读码中";
                    lab_dama1Time.Text = $"{GetTimeCount(GlobalVar.Instance.TimeStepData1.readSatrtTime, DateTime.Now)}";
                    lab_duma1.Visible = true;
                    lab_duma1Time.Visible = true;
                    lab_xialiao1.Visible = false;
                    lab_xialiao1Time.Visible = false;

                    ucdu1.IsFlow = true;
                }
                xialiao1();
            }
            else
            {
                lab_duma1.Visible = false;
                lab_duma1Time.Visible = false;
                lab_xialiao1.Visible = false;
                lab_xialiao1Time.Visible = false;
            }
        }

        private void xialiao1()
        {
            if (GlobalVar.Instance.TimeStepData1.xiaSatrtTime.Year > 1)
            {
                if (GlobalVar.Instance.TimeStepData1.xiaEndTime.Year > 1)
                {
                    lab_xialiao1.Text = $"搬运1-下料完成";
                    lab_xialiao1Time.Text = $"{GetTimeCount(GlobalVar.Instance.TimeStepData1.xiaSatrtTime, GlobalVar.Instance.TimeStepData1.xiaEndTime)}";
                }
                else
                {
                    lab_xialiao1.Text = $"搬运1-下料中";
                    lab_xialiao1Time.Text = $"{GetTimeCount(GlobalVar.Instance.TimeStepData1.xiaSatrtTime, DateTime.Now)}";
                    lab_xialiao1.Visible = false;
                    lab_xialiao1Time.Visible = false;

                    ucxia1.IsFlow = true;
                }
            }
            else
            {
                lab_xialiao1.Visible = false;
                lab_xialiao1Time.Visible = false;
            }
        }
        #endregion
        #region 搬运2
        private void qu2()
        {
            if (GlobalVar.Instance.TimeStepData2.quSatrtTime.Year > 1)
            {
                if (GlobalVar.Instance.TimeStepData2.quEndTime.Year > 1)
                {
                    lab_quliao2.Text = $"搬运1-取料完成";
                    lab_quliao2Time.Text = $"{GetTimeCount(GlobalVar.Instance.TimeStepData2.quSatrtTime, GlobalVar.Instance.TimeStepData2.quEndTime)}";
                }
                else
                {
                    lab_quliao2.Text = $"搬运1-取料中";
                    lab_quliao2Time.Text = $"{GetTimeCount(GlobalVar.Instance.TimeStepData2.quSatrtTime, DateTime.Now)}";
                    lab_quliao2.Visible = true;
                    lab_quliao2Time.Visible = true;
                    lab_jiance2.Visible = false;
                    lab_jiance2Time.Visible = false;
                    lab_dama2.Visible = false;
                    lab_dama2Time.Visible = false;
                    lab_duma2.Visible = false;
                    lab_duma2Time.Visible = false;
                    lab_xialiao2.Visible = false;
                    lab_xialiao2Time.Visible = false;


                    ucqu2.IsFlow = true;

                }
                jian2();
            }
            else
            {
                lab_quliao2.Visible = false;
                lab_quliao2Time.Visible = false;
                lab_jiance2.Visible = false;
                lab_jiance2Time.Visible = false;
                lab_dama2.Visible = false;
                lab_dama2Time.Visible = false;
                lab_duma2.Visible = false;
                lab_duma2Time.Visible = false;
                lab_xialiao2.Visible = false;
                lab_xialiao2Time.Visible = false;

                ucqu2.IsFlow = false;
                ucjian2.IsFlow = false;
                ucda2.IsFlow = false;
                ucdu2.IsFlow = false;
                ucxia2.IsFlow = false;
            }
        }

        private void jian2()
        {
            if (GlobalVar.Instance.TimeStepData2.checkSatrtTime.Year > 1)
            {
                if (GlobalVar.Instance.TimeStepData2.checkEndTime.Year > 1)
                {
                    lab_quliao2.Text = $"搬运1-检测完成";
                    lab_quliao2Time.Text = $"{GetTimeCount(GlobalVar.Instance.TimeStepData2.checkSatrtTime, GlobalVar.Instance.TimeStepData2.checkEndTime)}";
                }
                else
                {
                    lab_jiance2.Text = $"搬运1-检测中";
                    lab_jiance2Time.Text = $"{GetTimeCount(GlobalVar.Instance.TimeStepData2.checkSatrtTime, DateTime.Now)}";
                    lab_jiance2.Visible = true;
                    lab_jiance2Time.Visible = true;
                    lab_dama2.Visible = false;
                    lab_dama2Time.Visible = false;
                    lab_duma2.Visible = false;
                    lab_duma2Time.Visible = false;
                    lab_xialiao2.Visible = false;
                    lab_xialiao2Time.Visible = false;

                    ucjian2.IsFlow = true;
                }

                dama2();
            }
            else
            {
                lab_dama2.Visible = false;
                lab_dama2Time.Visible = false;
                lab_duma2.Visible = false;
                lab_duma2Time.Visible = false;
                lab_xialiao2.Visible = false;
                lab_xialiao2Time.Visible = false;
            }
        }

        private void dama2()
        {
            if (GlobalVar.Instance.TimeStepData2.printSatrtTime.Year > 1)
            {
                if (GlobalVar.Instance.TimeStepData2.printEndTime.Year > 1)
                {
                    lab_dama2.Text = $"搬运1-打码完成";
                    lab_dama2Time.Text = $"{GetTimeCount(GlobalVar.Instance.TimeStepData2.printSatrtTime, GlobalVar.Instance.TimeStepData2.printEndTime)}";
                }
                else
                {
                    lab_dama2.Text = $"搬运1-打码中";
                    lab_dama2Time.Text = $"{GetTimeCount(GlobalVar.Instance.TimeStepData2.printSatrtTime, DateTime.Now)}";
                    lab_dama2.Visible = true;
                    lab_dama2Time.Visible = true;
                    lab_duma2.Visible = false;
                    lab_duma2Time.Visible = false;
                    lab_xialiao2.Visible = false;
                    lab_xialiao2Time.Visible = false;

                    ucda2.IsFlow = true;
                }
                duma2();
            }
            else
            {
                lab_duma2.Visible = false;
                lab_duma2Time.Visible = false;
                lab_xialiao2.Visible = false;
                lab_xialiao2Time.Visible = false;
            }
        }

        private void duma2()
        {
            if (GlobalVar.Instance.TimeStepData2.readSatrtTime.Year > 1)
            {
                if (GlobalVar.Instance.TimeStepData2.readEndTime.Year > 1)
                {
                    lab_duma2.Text = $"搬运1-读码完成";
                    lab_duma2Time.Text = $"{GetTimeCount(GlobalVar.Instance.TimeStepData2.readSatrtTime, GlobalVar.Instance.TimeStepData2.readEndTime)}";
                }
                else
                {
                    lab_duma2.Text = $"搬运1-读码中";
                    lab_dama2Time.Text = $"{GetTimeCount(GlobalVar.Instance.TimeStepData2.readSatrtTime, DateTime.Now)}";
                    lab_duma2.Visible = true;
                    lab_duma2Time.Visible = true;
                    lab_xialiao2.Visible = false;
                    lab_xialiao2Time.Visible = false;

                    ucdu2.IsFlow = true;
                }
                xialiao2();
            }
            else
            {
                lab_duma2.Visible = false;
                lab_duma2Time.Visible = false;
                lab_xialiao2.Visible = false;
                lab_xialiao2Time.Visible = false;
            }
        }

        private void xialiao2()
        {
            if (GlobalVar.Instance.TimeStepData2.xiaSatrtTime.Year > 1)
            {
                if (GlobalVar.Instance.TimeStepData2.xiaEndTime.Year > 1)
                {
                    lab_xialiao2.Text = $"搬运1-下料完成";
                    lab_xialiao2Time.Text = $"{GetTimeCount(GlobalVar.Instance.TimeStepData2.xiaSatrtTime, GlobalVar.Instance.TimeStepData2.xiaEndTime)}";
                }
                else
                {
                    lab_xialiao2.Text = $"搬运1-下料中";
                    lab_xialiao2Time.Text = $"{GetTimeCount(GlobalVar.Instance.TimeStepData2.xiaSatrtTime, DateTime.Now)}";
                    lab_xialiao2.Visible = false;
                    lab_xialiao2Time.Visible = false;

                    ucxia2.IsFlow = true;
                }
            }
            else
            {
                lab_xialiao2.Visible = false;
                lab_xialiao2Time.Visible = false;
            }
        }
        #endregion

        private void UpdateData()
        {

            if (GlobalVar.Instance.TimeStepData1 != null)
            {
                lab1.Visible = true;

                if (GlobalVar.Instance.TimeStepData1.SatrtTime.Year > 1)
                {
                    if (GlobalVar.Instance.TimeStepData1.EndTime.Year > 1)
                    {
                        lab1.Text = $"搬运1-{GetTimeCount(GlobalVar.Instance.TimeStepData1.SatrtTime, GlobalVar.Instance.TimeStepData1.EndTime)}";
                    }
                    else
                    {
                        lab1.Text = $"搬运1-{GetTimeCount(GlobalVar.Instance.TimeStepData1.SatrtTime, DateTime.Now)}";
                    }
                    qu1();
                }
                else
                {
                    lab1.Visible = false;
                }

            }
            else
            {
                lab1.Visible = false;
                //
                lab_quliao1.Visible = false;
                lab_quliao1Time.Visible = false;
                lab_jiance1.Visible = false;
                lab_jiance1Time.Visible = false;
                lab_dama1.Visible = false;
                lab_dama1Time.Visible = false;
                lab_duma1.Visible = false;
                lab_duma1Time.Visible = false;
                lab_xialiao1.Visible = false;
                lab_xialiao1Time.Visible = false;
            }

            if (GlobalVar.Instance.TimeStepData2 != null)
            {
                if (GlobalVar.Instance.TimeStepData2.SatrtTime.Year > 1)
                {
                    lab2.Visible = true;
                    if (GlobalVar.Instance.TimeStepData2.EndTime.Year > 1)
                    {
                        lab2.Text = $"搬运2-{GetTimeCount(GlobalVar.Instance.TimeStepData2.SatrtTime, GlobalVar.Instance.TimeStepData2.EndTime)}";
                    }
                    else
                    {
                        lab2.Text = $"搬运2-{GetTimeCount(GlobalVar.Instance.TimeStepData2.SatrtTime, DateTime.Now)}";
                    }

                    qu2();
                }
                else
                {
                    lab2.Visible = false;
                }
            }
            else
            {
                lab2.Visible = false;
                //
                lab_quliao2.Visible = false;
                lab_quliao2Time.Visible = false;
                lab_jiance2.Visible = false;
                lab_jiance2Time.Visible = false;
                lab_dama2.Visible = false;
                lab_dama2Time.Visible = false;
                lab_duma2.Visible = false;
                lab_duma2Time.Visible = false;
                lab_xialiao2.Visible = false;
                lab_xialiao2Time.Visible = false;
            }
        }

    }
}
